//
//  NWStatus.swift
//  AFNetworking
//
//  Created by Northwan on 16/01/24
//  Copyright (c) __ORGANIZATIONNAME__. All rights reserved.
//

import UIKit

class NWStatus: NSObject {
    
    //微博id
    var id:Int64 = 0
    /// 微博内容
    var text: String?
    /// 转发数
    var reposts_count: Int = 0
    /// 评论数
    var comments_count: Int = 0
    /// 表态数
    var attitudes_count: Int = 0
    /// 微博作者
    var user: NWUser?
    /// 来源
    var source:String?
    /// 时间
    var created_at:String?
    ///配图
    var pic_urls: [NWStatusPhoto]?
    // 转发微博模型
    var retweeted_status: NWStatus?

    
    init(dict:[String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    
    //特殊的类型需要自己解析
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String: AnyObject]{
                user = NWUser(dict: dict)
            }
        }else if key == "pic_urls"{
            if let array = value as? [[String: AnyObject]]{
                var tempArray = [NWStatusPhoto]()
                for value in array {
                    tempArray.append(NWStatusPhoto(dict: value))
                }
                pic_urls = tempArray
            }
        }else if key == "retweeted_status"{
            if let dict = value as? [String: AnyObject]{
                retweeted_status = NWStatus(dict: dict)
            }
        }else{
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    
    override var description: String {
        let keys = ["text"]
        return dictionaryWithValuesForKeys(keys).description
    }
}